package com.dongdong.mq;

import com.dongdong.service.FreeMarketService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Deacription TODO
 * @Author Lenovo
 * @Date 2020/12/18 11:09
 * @Version 1.0
 **/
@Component
@RocketMQMessageListener(topic = "goods_topic",consumerGroup = "dongdongshop",messageModel = MessageModel.BROADCASTING)
public class ItemRocketMQ implements RocketMQListener<Long[]> {

    @Resource
    private FreeMarketService freeMarketService;

    @Override
    public void onMessage(Long[] goodsId) {
        try {
            for (Long id : goodsId) {
                freeMarketService.createItemPage(id);
                System.out.println("消费成功");
            }
        }catch (Exception e){
            System.out.println("消费失败");
        }
    }
}

